<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('任务调度GIT日志列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="busi:executionLog:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('busi:executionLog:edit')}]];
        var removeFlag = [[${@permission.hasPermi('busi:executionLog:remove')}]];
        var prefix = ctx + "busi/executionLog";
        var exeStatus = [[${@dict.getType('kt_exe_status')}]];
        var taskType = [[${@dict.getType('task_type')}]];
        var taskId = [[${taskId}]];

        var url = "";
        if (taskId === -1) {
            url = prefix + "/list";
        } else {
            url = prefix + "/list/"+taskId;
        }

        $(function() {
            var options = {
                url: url,
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "任务调度日志",
                sortName: "startTime",
                sortOrder: "DESC",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '日志ID',
                    visible: false
                },
                {
                    field: 'taskName',
                    title: '任务名称',
                    formatter: function(value, row, index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'startTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                {
                    field: 'executionMethod',
                    title: '执行方式'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(exeStatus, value);
                    }
                },
                {
                    field: 'taskType',
                    title: '任务类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(taskType, value);
                    }
                },
                    {
                        field: 'jobId',
                        title: '定时任务ID',
                    },
                    {
                        field: 'jobName',
                        title: '定时任务名称',
                    },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

            var _table = $.table;
            setInterval(function(){
                $.get("/getVersion","",function (data){
                    if (window["updateState"]) {
                        if (window["updateState"]["executionLog"] != data) {
                            _table.refresh()
                            window["updateState"]["executionLog"] = data;
                        }
                    } else {
                        window["updateState"] = {};
                        window["updateState"]["executionLog"] = 1;
                    }
                })
            }, 1000);

            $.table.refresh()
        });

        function detail(id) {
            var url = prefix + '/detail/' + id;
            // console.log("url="+ url)
            $.modal.openTab("日志详细信息", url);
        }
    </script>
</body>
</html>